package com.benefm.multipar.pad.util.filter;

import java.io.File;
import java.io.FileOutputStream;


public class EcgFilter {
    private final static int CHN = 12;
    private final static boolean ENABLE_NEW_FILTER = false;
    private final static int I_PACER_PLUS_VALUE = 74;
    private final static int II_PACER_PLUS_VALUE = 98;
    private final static int V_PACER_PLUS_VALUE = 41;
    /*
     * 40Hz低通
     */
    private final static int[] coffs_lp40_250 = new int[]{-1, -1, 2, 4, 0, -10, -9, 13, 31, 0,
            -62, -56, 90, 306, 410, 306, 90, -56, -62, 0,
            31, 13, -9, -10, 0, 4, 2, -1, -1};
    private static int lp40_250_index;
    private static int[][] lp40_250_buff;
    private final static int LP40_250_BUFF_LENGTH = 29;

    /*
     * 0.67Hz高通
     */
    private static int hp067_250_index;
    private static int[][] hp067_250_buff;
    private final static int HP067_250_BUFF_LENGTH = 500;
    //	private final static int HP067_250_BUFF_LENGTH = 550;//
    private final static int HP067_250_COL = (HP067_250_BUFF_LENGTH * HP067_250_BUFF_LENGTH) / 4;
    private static long[] hp067_250_buff_y1;
    private static long[] hp067_250_buff_y2;

    /*
     * 50Hz工频
     */
    private static int coffs_notch50_250_index;
    private static int[][] coffs_notch50_250_buff;
    private final static int COFFS_NOTCH50_250_BUFF_LENGTH = 345;

    private final static int[] coffs_notch50_250 = new int[]{
            -1, 0, 1, 0, -1, -1, 0, 1, 0, -1,
            -1, 0, 1, 0, -1, -1, 0, 1, 0, -1,
            -1, 0, 1, 0, -1, -1, 1, 2, 1, -2,
            -2, 1, 2, 1, -2, -2, 1, 3, 1, -2,
            -2, 1, 3, 1, -3, -3, 1, 4, 1, -3,
            -3, 1, 4, 1, -4, -4, 2, 5, 2, -5,
            -5, 2, 6, 2, -5, -5, 2, 7, 2, -6,
            -6, 2, 8, 3, -7, -7, 3, 9, 3, -8,
            -8, 3, 10, 3, -9, -9, 3, 11, 4, -9,
            -10, 4, 12, 4, -10, -11, 4, 13, 4, -11,
            -11, 4, 15, 5, -12, -12, 5, 16, 5, -13,
            -13, 5, 17, 5, -14, -14, 6, 18, 6, -15,
            -15, 6, 19, 6, -16, -16, 6, 20, 6, -17,
            -17, 6, 21, 7, -17, -17, 7, 22, 7, -18,
            -18, 7, 23, 7, -19, -19, 7, 23, 7, -19,
            -19, 7, 24, 7, -19, -20, 7, 24, 8, -20,
            -20, 8, 25, 8, -20, -20, 8, 25, 8, -20,
            -20, 8, 24, 8, -20, -20, 8, 25, 8, -20,
            -20, 8, 25, 8, -20, -20, 8, 24, 7, -20,
            -19, 7, 24, 7, -19, -19, 7, 23, 7, -19,
            -19, 7, 23, 7, -18, -18, 7, 22, 7, -17,
            -17, 7, 21, 6, -17, -17, 6, 20, 6, -16,
            -16, 6, 19, 6, -15, -15, 6, 18, 6, -14,
            -14, 5, 17, 5, -13, -13, 5, 16, 5, -12,
            -12, 5, 15, 4, -11, -11, 4, 13, 4, -11,
            -10, 4, 12, 4, -10, -9, 4, 11, 3, -9,
            -9, 3, 10, 3, -8, -8, 3, 9, 3, -7,
            -7, 3, 8, 2, -6, -6, 2, 7, 2, -5,
            -5, 2, 6, 2, -5, -5, 2, 5, 2, -4,
            -4, 1, 4, 1, -3, -3, 1, 4, 1, -3,
            -3, 1, 3, 1, -2, -2, 1, 3, 1, -2,
            -2, 1, 2, 1, -2, -2, 1, 2, 1, -1,
            -1, 0, 1, 0, -1, -1, 0, 1, 0, -1,
            -1, 0, 1, 0, -1, -1, 0, 1, 0, -1,
            -1, 0, 1, 0, -1};

    private static int coffs_notch50_250_new_index;
    private final static int COFFS_NOTCH50_250_NEW_BUFF_LENGTH = 45;
    private static int[][] coffs_notch50_250_new_buff;
    private final static int[] coffs_notch50_250_new = {
            -4, 2, 7, 2, -6, -7, 3, 10, 3, -9,
            -9, 4, 13, 4, -11, -11, 4, 15, 5, -12,
            -12, 5, 15, 5, -12, -12, 5, 15, 4, -11,
            -11, 4, 13, 4, -9, -9, 3, 10, 3, -7,
            -6, 2, 7, 2, -4
    };


    /*
     * 起搏
     */
    private static int[][] pace_buf;
    private static int[] wave_base;
    private static int pace_buf_index = 0;
    private static int pace_buf_PreIndex = 0;
    private final static int PACE_BUFF_LENGTH = 436;//411;//411;
    private final static int PACE_HP_BUFF_LENGTH = 422;//397;//411;
    private final static int MAX_PACER_PLUS_CNT = 5; // 8-->5;
    private final static int MIN_PACER_PLUS_CNT = 3; // 3-->2
    private final static int VALID_AV_INTERVAL = 25;        // 最小AV间期为100ms，及25个点
    private final static int HALF_QUEUE_DATA_LENGTH = (VALID_AV_INTERVAL + 0);
    private final static int MAX_PACER_BUF_LENGTH = (HALF_QUEUE_DATA_LENGTH + HALF_QUEUE_DATA_LENGTH); // (MAX_PACER_PLUS_CNT+VALID_AV_INTERVAL+MAX_PACER_PLUS_CNT);
    private static int DATA_OFFSET = HALF_QUEUE_DATA_LENGTH;
    private static int mPacerPlusCnt;

    private static int DELAY_CNT;
    private static boolean isEnableFillData;
    private static int mFillDataCnt;
    private static int mFillDataIndex;
    private int mCopyDataIndex;
    private static int SRC_ECG_DATA_CNT_PER_LEAD;
    private int mEcgDataIndexBuff[];
    private short mSrcEcgDataBuff[];        // 原始数据与滤波数据延时一致

    private int[] ecg_in_UnPacer;
    private boolean mbFakePace;            //伪起搏标志
    private int mPreValidDataNum;        // 前面有效数据长度
    private int mPrePacerFlagNum;        // 前面连续起搏标记长度
    private int mNewPacerFlagNum;        // 新连续起搏标记长度

    private int[][] marrFilterDelayBuf;        // [CHN+1][MAX_PACER_BUF_LENGTH]

    private long hpDisableStart = System.currentTimeMillis();
    private int HP_TIME_ENALBE = 6000;
    private boolean baseTimeEnable = false;
    private short[] baseTempData;
    private int startIndex;
    private int[] oneLeadTempData;
    private short[][] tempAllData;
    private int[] baseline = new int[12];
    private boolean baselineEnable = false;
    private boolean enableHPFilter = true;


    private short[] orgEcgData;

    public EcgFilter() {
        OnInit();
    }

    public void OnInit() {
        int i, j;
        setEnableHPFilter(true);
        isEnableFillData = false;
        mFillDataCnt = 0;
        mFillDataIndex = 0;
        mCopyDataIndex = 0;
        SRC_ECG_DATA_CNT_PER_LEAD = 0;
        DELAY_CNT = getFilterDelay();
        mSrcEcgDataBuff = null;
        mEcgDataIndexBuff = null;

        mPacerPlusCnt = 0;
        lp40_250_index = 0;
        lp40_250_buff = new int[LP40_250_BUFF_LENGTH][CHN];
        for (i = 0; i < LP40_250_BUFF_LENGTH; i++) {
            for (j = 0; j < lp40_250_buff[i].length; j++) {
                lp40_250_buff[i][j] = 0;
            }
        }

        hp067_250_index = 0;
        hp067_250_buff = new int[HP067_250_BUFF_LENGTH][CHN];
        for (i = 0; i < HP067_250_BUFF_LENGTH; i++) {
            for (j = 0; j < hp067_250_buff[i].length; j++) {
                hp067_250_buff[i][j] = 0;
            }
        }
        hp067_250_buff_y1 = new long[CHN];
        for (j = 0; j < hp067_250_buff_y1.length; j++) {
            hp067_250_buff_y1[j] = 0;
        }
        hp067_250_buff_y2 = new long[CHN];
        for (j = 0; j < hp067_250_buff_y2.length; j++) {
            hp067_250_buff_y2[j] = 0;
        }


        coffs_notch50_250_index = 0;
        coffs_notch50_250_buff = new int[COFFS_NOTCH50_250_BUFF_LENGTH][CHN];
        for (i = 0; i < COFFS_NOTCH50_250_BUFF_LENGTH; i++) {
            for (j = 0; j < coffs_notch50_250_buff[i].length; j++) {
                coffs_notch50_250_buff[i][j] = 0;
            }
        }

        coffs_notch50_250_new_index = 0;
        coffs_notch50_250_new_buff = new int[COFFS_NOTCH50_250_NEW_BUFF_LENGTH][CHN];
        for (i = 0; i < COFFS_NOTCH50_250_NEW_BUFF_LENGTH; i++) {
            for (j = 0; j < coffs_notch50_250_new_buff[i].length; j++) {
                coffs_notch50_250_new_buff[i][j] = 0;
            }
        }


        pace_buf = new int[PACE_BUFF_LENGTH][CHN + 1];
        wave_base = new int[CHN];

        for (i = 0; i < PACE_BUFF_LENGTH; i++) {
            for (j = 0; j < pace_buf[i].length; j++) {
                pace_buf[i][j] = 0;
            }
        }
        for (j = 0; j < wave_base.length; j++) {
            wave_base[j] = 0;
        }


        ecg_in_UnPacer = new int[CHN + 1];
        mbFakePace = false;
        mPreValidDataNum = 0;
        mPrePacerFlagNum = 0;
        mNewPacerFlagNum = 0;
        pace_buf_index = 0;
        pace_buf_PreIndex = 0;

        marrFilterDelayBuf = new int[CHN + 1][MAX_PACER_BUF_LENGTH];
        for (i = 0; i < CHN + 1; i++) {
            for (j = 0; j < MAX_PACER_BUF_LENGTH; j++) {
                marrFilterDelayBuf[i][j] = 0;
            }
        }
        System.out.println("滤波版本号：v1.0");
    }

    int CURR_DELAY_CNT_BAK;

    /**
     * 滤波
     *
     * @param ecgDataBuf      原始数据缓冲区AABB（最后1个通道必须为起搏导联）
     * @param xLeadDictionary 导联字典
     * @param bABAB           ecgDataBuf中数据是否为ABAB格式
     * @param isEnableLP      是否开启低通滤波
     * @return 滤波后的数据
     */
    public short[] doFilter(short[] ecgDataBuf, byte[] xLeadDictionary, boolean bABAB, boolean isEnableLP) {
        int i, j;
        short leadIndex = 0;
        short leadNum;
        short LEAD_COUNT;
        short filterLeadCount = 0;
        short[] xFilterOutBuf = null;    // 返回滤波后的数据
        int length;
        int CURR_DELAY_CNT = 0;
        boolean bPacer = false;    // 是否有起搏通道
        int nDataCntPerLead = 0;

        do {
            if (null == ecgDataBuf) {
                break;
            }
            if (null == xLeadDictionary) {
                break;
            }

            LEAD_COUNT = (short) xLeadDictionary.length;
            if (0 == LEAD_COUNT) {
                break;
            }
            if (0 != ecgDataBuf.length % LEAD_COUNT) {
                System.out.println("doFilter :: ecgDataBuf.length%LEAD_COUNT = " + (ecgDataBuf.length % LEAD_COUNT) + "  !!!!!!!!");
                break;
            }
            nDataCntPerLead = ecgDataBuf.length / LEAD_COUNT;
            if (0 >= nDataCntPerLead) {
                break;
            }
            for (i = 0, filterLeadCount = 0; i < xLeadDictionary.length; i++) {
                if (EcgDataContext.MAX_ECG_LEAD <= xLeadDictionary[i]) {
                    continue;
                }
                if (EcgDataContext.LEAD_Pacer == xLeadDictionary[i]) {
                    bPacer = true;
                    continue;
                }
                if (EcgDataContext.LEAD_V5R <= xLeadDictionary[i]) {
                    continue;
                }
                filterLeadCount++;
            }
            if (0 == filterLeadCount) {
                break;
            }
//			System.out.println("leadCnt = "+LEAD_COUNT+"  filterLeadCount = "+filterLeadCount+"  dateCntPerLead = "+nDataCntPerLead);

            int offset = 0;
            int[] filterOutBuf = new int[nDataCntPerLead * filterLeadCount];
            if (null == filterOutBuf) {
                break;
            }

            if (0 >= SRC_ECG_DATA_CNT_PER_LEAD) {
                SRC_ECG_DATA_CNT_PER_LEAD = DELAY_CNT + nDataCntPerLead * 2;
            }
            if (null == mEcgDataIndexBuff) {
                mEcgDataIndexBuff = new int[filterLeadCount];
                for (i = 0; i < filterLeadCount; i++) {
                    mEcgDataIndexBuff[i] = i * SRC_ECG_DATA_CNT_PER_LEAD;
                }
            }
            if (null == mSrcEcgDataBuff) {
                offset = SRC_ECG_DATA_CNT_PER_LEAD * filterLeadCount;
                mSrcEcgDataBuff = new short[offset];
                for (i = 0; i < SRC_ECG_DATA_CNT_PER_LEAD; i++) {
                    mSrcEcgDataBuff[i] = 0;
                }
                offset = 0;
            }
//			mFillDataIndex = 0;
            int[] filterOutMergePaceBuf = new int[nDataCntPerLead * (filterLeadCount + 1)];
            int[] pacerPosBuf = new int[nDataCntPerLead];
            if (isEnableLP) {
                CURR_DELAY_CNT = PACE_HP_BUFF_LENGTH;
            } else {
                CURR_DELAY_CNT = PACE_BUFF_LENGTH;
            }
            if (CURR_DELAY_CNT != CURR_DELAY_CNT_BAK) {
                CURR_DELAY_CNT_BAK = CURR_DELAY_CNT;
            }
            // 滤波
            filter(filterOutBuf, filterOutMergePaceBuf, ecgDataBuf, pacerPosBuf, nDataCntPerLead, filterLeadCount, bABAB, isEnableLP);

            int copyDataLength;
            short[] _pLeadData = new short[nDataCntPerLead];

            //输出
            xFilterOutBuf = new short[filterOutBuf.length];
            for (i = 0; i < filterLeadCount; i++) {
                if (EcgDataContext.MAX_ECG_LEAD <= i) {
                    continue;
                }
                leadIndex = xLeadDictionary[i];
                if (EcgDataContext.LEAD_Pacer == leadIndex) {
                    continue;
                }
                if (EcgDataContext.MAX_ECG_LEAD <= leadIndex) {
                    continue;
                }
                offset = (int) (i * nDataCntPerLead);
                for (j = 0; j < nDataCntPerLead; j++) {    //ABAB转AABB
                    _pLeadData[j] = (short) filterOutBuf[j * filterLeadCount + i];//[j*filterLeadCount + i];/* = pPack->GetDataByLeadIndex(i)[j];*/
                }
                System.arraycopy(_pLeadData, 0, xFilterOutBuf, offset, nDataCntPerLead);
            }

        } while (false);

        return xFilterOutBuf;
    }

    private boolean isNewCal = true;
    private int ECG_BUF_SIZE = 15;

    private void calEcgFilterData(short[] data, int dataLen, int leadCount) {
        do {
            if (orgEcgData == null) {
                orgEcgData = new short[dataLen];
            }
            System.arraycopy(data, 0, orgEcgData, 0, dataLen);

            int oneLeadCount = dataLen / leadCount;

            oneLeadCount = 50;

            if (baselineEnable) {
                for (int i = 0; i < leadCount; i++) {
                    for (int j = 0; j < oneLeadCount; j++) {
//						if(Math.abs(baseline[i]) < 10)
//						{
//							continue ;
//						}
                        data[i * oneLeadCount + j] = (short) (data[i * oneLeadCount + j] - baseline[i]);
                    }
                }
            }

            if (System.currentTimeMillis() - hpDisableStart > HP_TIME_ENALBE) {
                baseTimeEnable = true;
            }

            if (!baseTimeEnable) {
                break;
            }

            if (isNewCal) {
                if (oneLeadTempData == null) {
                    oneLeadTempData = new int[oneLeadCount * ECG_BUF_SIZE];
                }

                if (tempAllData == null) {
                    tempAllData = new short[12][oneLeadCount * ECG_BUF_SIZE];
                }

                if (startIndex < ECG_BUF_SIZE) {
                    for (int i = 0; i < leadCount; i++) {
                        for (int j = 0; j < oneLeadCount; j++) {
                            tempAllData[i][j + startIndex * oneLeadCount] = orgEcgData[i * oneLeadCount + j];
                        }
                    }
                    startIndex++;
                } else if (startIndex == ECG_BUF_SIZE) {
                    calbaseline(leadCount);
                } else {
                    startIndex = 0;
                }
                break;
            }
        } while (false);
    }

    FileOutputStream ecgOutputStream, baselineStream;
    File outFile, baselineTxt;
    private boolean save = false;

    static void Sort16S(short arr[], int n) {
        int i, j, k;
        short t;
        {
            for (i = 0; i < n - 1; i++) {
                k = i;
                for (j = i + 1; j < n; j++) {
                    if (arr[j] < arr[k]) {
                        k = j;
                    }
                }
                t = arr[k];
                arr[k] = arr[i];
                arr[i] = t;
            }
        }
    }

//    // 保存滤波后的数据
//    private void saveData(short[] saveData, int baseline, int index) {
//        try {
//            if (!save) {
//                if (outFile == null) {
//                    outFile = new File("/home/filter.dat");
//                }
//
//                if (!outFile.exists()) {
//                    outFile.createNewFile();
//                }
//
//                if (baselineTxt == null) {
//                    baselineTxt = new File("/home/baseline.txt");
//                }
//
//                if (!baselineTxt.exists()) {
//                    baselineTxt.createNewFile();
//                }
//
//                if (ecgOutputStream == null) {
//                    ecgOutputStream = new FileOutputStream(outFile, true);
//                }
//
//                if (baselineStream == null) {
//                    baselineStream = new FileOutputStream(baselineTxt, true);
//                }
//
//                for (int i = 0; i < saveData.length; i++) {
//                    ecgOutputStream.write(StringUtil.shortToByteArray(saveData[i]));
//                }
//                ecgOutputStream.flush();
//
//                baselineStream.write(("i : " + index + "  " + baseline + "  \n").getBytes());
//                baselineStream.flush();
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }

    private void calbaseline(int leadCnt) {
        for (int i = 0; i < leadCnt; i++) {
            for (int s = 0; s < oneLeadTempData.length; s++) {
                oneLeadTempData[s] = 0;
            }

            for (int j = 0; j < tempAllData[i].length; j++) {
                oneLeadTempData[j] = tempAllData[i][j];
            }

            voSort32Bit(oneLeadTempData, oneLeadTempData.length);
//			Sort16S(oneLeadTempData , oneLeadTempData.length) ;

            int m = oneLeadTempData.length / 2;
            int n = m + oneLeadTempData.length / 8;
            m = m - oneLeadTempData.length / 8;

            int lslCnt, lslTmp, k;
            for (k = m, lslTmp = 0, lslCnt = 0; k < n; k++) {
                lslTmp += oneLeadTempData[k];
                lslCnt++;
            }

            int curbl = 0;

            if (0 <= lslTmp) {
                curbl = (lslTmp / lslCnt);
            } else {
                curbl = -((-lslTmp) / lslCnt);
            }

//			if(Math.abs(Math.abs(curbl) - Math.abs(baseline[i])) < 10)
//			{
//				continue ;
//			}

            baseline[i] = curbl;
        }
        save = true;
        baselineEnable = true;
        startIndex = 0;
    }

    private void voSort32Bit(int[] voDataBuf, int usLen) {
        int i, j, k, x;
        int lusLen = (int) usLen;

        k = lusLen / 2;
        while (k >= 1) {
            for (i = k; i < lusLen; i++) {
                x = voDataBuf[i];
                j = i - k;
                while (j >= 0 && x < voDataBuf[j]) {
                    voDataBuf[j + k] = voDataBuf[j];
                    j -= k;
                }
                voDataBuf[j + k] = x;
            }
            k /= 2;
        }
    }

    // 40Hz低通滤波
    static void lp40_250(int data_in[], int data_out[], int nLeadCount) {
        int i, j;
        int x_ptr;
        long y;

        if (0 < nLeadCount) {
            if (LP40_250_BUFF_LENGTH <= lp40_250_index) {
                lp40_250_index = 0;
            }

            for (i = 0; i < nLeadCount; ++i) {
                x_ptr = lp40_250_index;
                lp40_250_buff[x_ptr][i] = data_in[i];
                y = 0;
                for (j = 0; j < LP40_250_BUFF_LENGTH; ++j) {
                    y += coffs_lp40_250[j] * lp40_250_buff[x_ptr][i];
                    if (--x_ptr < 0) {
                        x_ptr = LP40_250_BUFF_LENGTH - 1;
                    }
                }
                data_out[i] = (int) (y >> 10);
            }

            if (++lp40_250_index == LP40_250_BUFF_LENGTH) {
                lp40_250_index = 0;
            }
        }
    }

    // 0.67Hz高通
    static void hp067_250(int data_in[], int data_out[], int nLeadCount) {

        int i;
        long y;
        int half_ptr;

        if (0 < nLeadCount) {
            if (HP067_250_BUFF_LENGTH <= hp067_250_index) {
                hp067_250_index = 0;
            }

            half_ptr = hp067_250_index - (HP067_250_BUFF_LENGTH / 2);
            if (half_ptr < 0) {
                half_ptr += HP067_250_BUFF_LENGTH;
            }

            for (i = 0; i < nLeadCount; ++i) {
                y = 2 * hp067_250_buff_y1[i] - hp067_250_buff_y2[i] + data_in[i] - 2 * hp067_250_buff[half_ptr][i] + hp067_250_buff[hp067_250_index][i];
                hp067_250_buff_y2[i] = hp067_250_buff_y1[i];
                hp067_250_buff_y1[i] = y;
                hp067_250_buff[hp067_250_index][i] = data_in[i];
                data_out[i] = hp067_250_buff[half_ptr][i] - (int) (y / HP067_250_COL);//50625);
            }
            if (++hp067_250_index == HP067_250_BUFF_LENGTH) {
                hp067_250_index = 0;
            }
        }
    }

    // 50Hz工频陷波
    static void notch50_250(int data_in[], int data_out[], int nLeadCount) {
        int i, j;
        int x_ptr;
        long y;
        int half_ptr;

        if (0 < nLeadCount) {
            if (COFFS_NOTCH50_250_BUFF_LENGTH <= coffs_notch50_250_index) {
                coffs_notch50_250_index = 0;
            }

            half_ptr = coffs_notch50_250_index - (COFFS_NOTCH50_250_BUFF_LENGTH / 2);//172;
            if (half_ptr < 0) {
                half_ptr += COFFS_NOTCH50_250_BUFF_LENGTH;
            }

            for (i = 0; i < nLeadCount; ++i) {
                x_ptr = coffs_notch50_250_index;
                coffs_notch50_250_buff[x_ptr][i] = data_in[i];
                y = 0;
                for (j = 0; j < COFFS_NOTCH50_250_BUFF_LENGTH; ++j) {
                    y += coffs_notch50_250[j] * coffs_notch50_250_buff[x_ptr][i];
                    if (--x_ptr < 0) {
                        x_ptr = COFFS_NOTCH50_250_BUFF_LENGTH - 1;
                    }
                }
                data_out[i] = coffs_notch50_250_buff[half_ptr][i] - (int) (y >> 11);//y / 2048;
            }

            if (++coffs_notch50_250_index == COFFS_NOTCH50_250_BUFF_LENGTH) {
                coffs_notch50_250_index = 0;
            }
        }
    }

    /*
     * 50Hz新滤波算法
     */
    static void notch50_250_new(int data_in[], int data_out[]) {
        int i, j;
        int x_ptr;
        long y;
        int half_ptr;

        if (COFFS_NOTCH50_250_NEW_BUFF_LENGTH <= coffs_notch50_250_new_index) {
            coffs_notch50_250_new_index = 0;
        }

        half_ptr = coffs_notch50_250_new_index - COFFS_NOTCH50_250_NEW_BUFF_LENGTH / 2;
        if (half_ptr < 0) {
            half_ptr += COFFS_NOTCH50_250_NEW_BUFF_LENGTH;
        }

        for (i = 0; i < CHN; ++i) {
            x_ptr = coffs_notch50_250_new_index;
            coffs_notch50_250_new_buff[x_ptr][i] = data_in[i];
            y = 0;
            for (j = 0; j < COFFS_NOTCH50_250_NEW_BUFF_LENGTH; ++j) {
                y += coffs_notch50_250_new[j] * coffs_notch50_250_new_buff[x_ptr][i];
                if (--x_ptr < 0) {
                    x_ptr = COFFS_NOTCH50_250_NEW_BUFF_LENGTH - 1;
                }
            }
            data_out[i] = coffs_notch50_250_new_buff[half_ptr][i] - (int) (y / 256);
        }

        if (++coffs_notch50_250_new_index == COFFS_NOTCH50_250_NEW_BUFF_LENGTH) {
            coffs_notch50_250_new_index = 0;
        }
    }


    void bp067_40_250(int data_in[], int data_out[], int nLeadCount) {
        int i;
        int[] notch_out;// = new int [CHN];
        int[] lp_out;// = new int [CHN];
        int leadNum;

        if (0 < nLeadCount) {
            notch_out = new int[nLeadCount];
            lp_out = new int[nLeadCount];

            //	notch50_250_new(data_in, notch_out);
            notch50_250(data_in, notch_out, nLeadCount);
//		if(!isEnableHPFilter())
//		{
//			lp40_250(notch_out, lp_out);
//			hp067_250(lp_out, data_out);
//		}
//		else
            {
                hp067_250(notch_out, data_out, nLeadCount);
            }

            leadNum = mEcgDataIndexBuff.length > data_in.length ? data_in.length : mEcgDataIndexBuff.length;
            mFillDataIndex = mFillDataIndex % SRC_ECG_DATA_CNT_PER_LEAD;
            if (isEnableFillData) {
                for (i = 0; i < leadNum; i++) {
                    mSrcEcgDataBuff[mEcgDataIndexBuff[i] + mFillDataIndex] = (short) (data_in[i]);
                }
            } else {
                for (i = 0; i < leadNum; i++) {
                    mSrcEcgDataBuff[mEcgDataIndexBuff[i] + mFillDataIndex] = 0;
                }
            }
            mFillDataIndex++;
            mFillDataIndex = mFillDataIndex % SRC_ECG_DATA_CNT_PER_LEAD;
            if (!isEnableFillData) {
                mFillDataCnt++;
            }
            if (DELAY_CNT <= mFillDataCnt) {
                isEnableFillData = true;
            }
        }
    }

    // 总延迟为411个采样点
    /*
     * isEnableLP——是否允许低通滤波
     */
    void bp067_40_250(int data_in[], int data_out[], int nLeadCount, boolean isEnalbeLP) {
        int i = 0;
        int[] notch_out;// = new int [CHN];
        int[] lp_out;// = new int [CHN];
        int leadNum;

        if (0 < nLeadCount) {
            notch_out = new int[nLeadCount];
            lp_out = new int[nLeadCount];

            notch50_250(data_in, notch_out, nLeadCount);
            if (isEnalbeLP) {
                lp40_250(notch_out, lp_out, nLeadCount);
                hp067_250(lp_out, data_out, nLeadCount);
            } else {
                hp067_250(notch_out, data_out, nLeadCount);
            }
            leadNum = mEcgDataIndexBuff.length > data_in.length ? data_in.length : mEcgDataIndexBuff.length;
            mFillDataIndex = mFillDataIndex % SRC_ECG_DATA_CNT_PER_LEAD;

            if (isEnableFillData) {
                for (i = 0; i < leadNum; i++) {
                    mSrcEcgDataBuff[mEcgDataIndexBuff[i] + mFillDataIndex] = (short) (data_in[i]);
                }
            } else {
                for (i = 0; i < leadNum; i++) {
                    mSrcEcgDataBuff[mEcgDataIndexBuff[i] + mFillDataIndex] = 0;
                }
            }
            mFillDataIndex++;
            mFillDataIndex = mFillDataIndex % SRC_ECG_DATA_CNT_PER_LEAD;

            if (!isEnableFillData) {
                mFillDataCnt++;
            }
            if (DELAY_CNT <= mFillDataCnt) {
                isEnableFillData = true;
            }
        }
    }


    // 具有起搏通道时的滤波
    int[] filter_pace(int ecg_in[], int ecg_outPaceBuf[]) {
        int i;
        int flag = 0;
        int[] ecg_out = new int[CHN];

        if (isEnableHPFilter()) {
            if (PACE_HP_BUFF_LENGTH <= pace_buf_index) {
                pace_buf_index = 0;
            }
        } else {
            if (PACE_BUFF_LENGTH <= pace_buf_index) {
                pace_buf_index = 0;
            }
        }


        if (ecg_in[12] != 0) {
            for (i = 0; i < CHN; ++i) {
                pace_buf[pace_buf_index][i] = ecg_in[i] - wave_base[i];
            }
        } else {
            for (i = 0; i < CHN; ++i) {
                pace_buf[pace_buf_index][i] = 0;
                wave_base[i] = ecg_in[i];
            }
        }
        bp067_40_250(wave_base, ecg_out, CHN);
        System.arraycopy(ecg_out, 0, ecg_outPaceBuf, 0, ecg_out.length);
//		if (++pace_buf_index == PACE_BUFF_LENGTH) {
//			pace_buf_index = 0;
//		}

        if (isEnableHPFilter()) {
            if (++pace_buf_index == PACE_HP_BUFF_LENGTH) {
                pace_buf_index = 0;
            }
        } else {
            if (++pace_buf_index == PACE_BUFF_LENGTH) {
                pace_buf_index = 0;
            }
        }


        for (i = 0; i < CHN; ++i) {
            if (pace_buf[pace_buf_index][i] != 0) {
                flag = 1;
                break;
            }
        }
        if (flag == 1) {
            for (i = 0; i < CHN; ++i) {
                if (EcgDataContext.LEAD_I == i) {
                    ecg_out[i] += I_PACER_PLUS_VALUE;
                } else if (EcgDataContext.LEAD_II == i) {
                    ecg_out[i] += II_PACER_PLUS_VALUE;
                } else {
                    ecg_out[i] += V_PACER_PLUS_VALUE;//脉冲高度为0.5mV	// += pace_buf[pace_buf_index][i];
                }
//				ecg_out[i] += pace_buf[pace_buf_index][i];
            }
        }

        return ecg_out;
    }

    void preShiffFilterDelayBuf(int nLeadCount) {
        int i, j;

        if (0 < nLeadCount) {
            for (i = 0; i < nLeadCount + 1; i++) {
                for (j = 1; j < MAX_PACER_BUF_LENGTH; j++)
                    marrFilterDelayBuf[i][j - 1] = marrFilterDelayBuf[i][j];
            }
        }
    }

    // 前面非起搏
    boolean getValidPacerFlagFromPreUnPacer() {
        int i;
        boolean bFlag = false;

        if (EcgDataContext.PACER_PLUS_MARK == marrFilterDelayBuf[CHN][DATA_OFFSET]) {
            if (mbFakePace) {    // 前面已经检测出非起搏
                mPreValidDataNum++;
                marrFilterDelayBuf[CHN][DATA_OFFSET] = EcgDataContext.FAKE_PACER_PLUS_MARK;    // 设置为非起搏
            } else {
                for (i = DATA_OFFSET - 1, mPreValidDataNum = 0; i >= 0; i--) {
                    if (0 == marrFilterDelayBuf[CHN][i]) {
                        mPreValidDataNum++;
                    } else {
                        break;
                    }
                }
                for (i = DATA_OFFSET, mNewPacerFlagNum = 0; i < marrFilterDelayBuf[CHN].length; i++) {
                    if (EcgDataContext.PACER_PLUS_MARK == marrFilterDelayBuf[CHN][i]) {
                        mNewPacerFlagNum++;
                    } else {
                        break;
                    }
                }
                if ((VALID_AV_INTERVAL > mPreValidDataNum) ||
                        (MIN_PACER_PLUS_CNT > mNewPacerFlagNum) ||
                        (MAX_PACER_PLUS_CNT < mNewPacerFlagNum)) {    // AV不足100ms，起搏个数＜3，起搏个数＞6 :: 当前不是起搏
                    if (!mbFakePace) {
                        System.out.println("  ++ 设置【伪起搏】  PDN = " + mPreValidDataNum + "  NPN = " + mNewPacerFlagNum);
                    }
                    mbFakePace = true;
                    mPreValidDataNum++;
                    marrFilterDelayBuf[CHN][DATA_OFFSET] = EcgDataContext.FAKE_PACER_PLUS_MARK;    // 设置为非起搏
                } else {
                    if (0 == mPacerPlusCnt) {
                        System.out.println("  +- 检测到【起搏】  PDN = " + mPreValidDataNum + "  NPN = " + mNewPacerFlagNum);
                    }

                    mbFakePace = false;
                    bFlag = true;
                }
            }
        } else {
            mbFakePace = false;
            mPreValidDataNum++;
        }

        return bFlag;
    }

    // 前面有起搏---有效起搏
    boolean getValidPacerFlagFromPrePacer() {
        int i;
        boolean bFlag = false;

        if (EcgDataContext.PACER_PLUS_MARK == marrFilterDelayBuf[CHN][DATA_OFFSET]) {
            if (mbFakePace) {    // 前面已经检测出非起搏
                mPreValidDataNum++;
                marrFilterDelayBuf[CHN][DATA_OFFSET] = EcgDataContext.FAKE_PACER_PLUS_MARK;    // 设置为非起搏
            } else {    // 统计前后起搏数量
                for (i = DATA_OFFSET - 1, mPrePacerFlagNum = 0; i >= 0; i--) {
                    if (EcgDataContext.PACER_PLUS_MARK == marrFilterDelayBuf[CHN][i]) {
                        mPrePacerFlagNum++;
                    } else {
                        break;
                    }
                }
                for (i = DATA_OFFSET, mNewPacerFlagNum = 0; i < marrFilterDelayBuf[CHN].length; i++) {
                    if (EcgDataContext.PACER_PLUS_MARK == marrFilterDelayBuf[CHN][i]) {
                        mNewPacerFlagNum++;
                    } else {
                        break;
                    }
                }
                if ((MIN_PACER_PLUS_CNT > (mPrePacerFlagNum + mNewPacerFlagNum)) ||
                        (MAX_PACER_PLUS_CNT < (mPrePacerFlagNum + mNewPacerFlagNum))) {    // 起搏个数＜3，起搏个数＞6 :: 当前不是起搏
                    if (!mbFakePace) {
                        System.out.println("  == 设置【伪起搏】  PDN = " + mPreValidDataNum + "  P_NUM = " + (mPrePacerFlagNum + mNewPacerFlagNum) + "     ------");
                    }
                    mbFakePace = true;
                    mPreValidDataNum++;
                    marrFilterDelayBuf[CHN][DATA_OFFSET] = EcgDataContext.FAKE_PACER_PLUS_MARK;    // 设置为非起搏
                } else {
                    if (0 == mPacerPlusCnt) {
                        System.out.println("  == 检测到【起搏】  PDN = " + mPreValidDataNum + "  P_NUM = " + (mPrePacerFlagNum + mNewPacerFlagNum) + "     ------");
                    }
                    mbFakePace = false;
                    bFlag = true;
                }
            }
        } else {
            mbFakePace = false;
            mPreValidDataNum++;
        }
        return bFlag;
    }

    boolean getValidPacerFlag() {
        boolean bFlag = false;

        if (EcgDataContext.PACER_PLUS_MARK == marrFilterDelayBuf[CHN][DATA_OFFSET - 1]) {
            bFlag = getValidPacerFlagFromPrePacer();
        } else {
            bFlag = getValidPacerFlagFromPreUnPacer();
        }
        return bFlag;
    }

    // 具有起搏通道时的滤波：增加延时
    int[] filter_pace_delay(int ecg_in[], int ecg_outPaceBuf[], int nLeadCount, boolean isEnalbeLP, boolean[] isPacer) {
        int i;
        int[] ecg_out = null;// = new int[CHN];
        int[] ecg_in_Pacer = null;// = new int[CHN+1];
        boolean bValidPacerFlag = false;

        do {
            if (null == ecg_in) {
                System.out.println("filter_pace_delay :: if(null == ecg_in)" + "  !!!!!!!!!!!!1");
                break;
            }
            if (null == pace_buf) {
                System.out.println("  filter_pace_delay :: if(null == pace_buf)" + "  !!!!!!!!!!!!1");
                break;
            }
            if (0 >= nLeadCount) {
                System.out.println("  filter_pace_delay :: nLeadCount = " + nLeadCount + "  !!!!!!!!!!!!1");
                break;
            }
            ecg_out = new int[nLeadCount];
            ecg_in_Pacer = new int[nLeadCount + 1];
            if (null == ecg_in_Pacer) {
                System.out.println("  filter_pace_delay :: if(null == ecg_in_Pacer)" + "  !!!!!!!!!!!!1");
                break;
            }
            if (null == ecg_out) {
                System.out.println("  filter_pace_delay :: if(null == ecg_out)" + "  !!!!!!!!!!!!1");
                break;
            }
            preShiffFilterDelayBuf(nLeadCount);
            for (i = 0; i < nLeadCount; i++) {
                ecg_out[i] = marrFilterDelayBuf[i][0];
                marrFilterDelayBuf[i][MAX_PACER_BUF_LENGTH - 1] = ecg_in[i];
            }
            marrFilterDelayBuf[nLeadCount][MAX_PACER_BUF_LENGTH - 1] = ecg_in[nLeadCount];    // 起搏通道
            bValidPacerFlag = getValidPacerFlag();
            for (i = 0; i < nLeadCount + 1; i++) {
                ecg_in_Pacer[i] = marrFilterDelayBuf[i][DATA_OFFSET];
            }

            if (isEnalbeLP) {
                if (PACE_HP_BUFF_LENGTH <= pace_buf_index) {
                    pace_buf_index = 0;
                }
            } else {
                if (PACE_BUFF_LENGTH <= pace_buf_index) {
                    pace_buf_index = 0;
                }
            }
            if (bValidPacerFlag) {
                if (0 == mPacerPlusCnt) {
                    if (pace_buf.length <= pace_buf_PreIndex) {
                        pace_buf_PreIndex = 0;
                    }
                    for (i = 0; i < nLeadCount; ++i) {
                        ecg_in_UnPacer[i] = pace_buf[pace_buf_PreIndex][i];
                    }
                }
                pace_buf[pace_buf_index][nLeadCount] = 1;
                mPacerPlusCnt++;
            } else {
                mPacerPlusCnt = 0;
                pace_buf[pace_buf_index][nLeadCount] = 0;
            }

            bp067_40_250(ecg_in_Pacer, ecg_out, nLeadCount, isEnalbeLP);

            for (i = 0; i < nLeadCount; ++i) {
                pace_buf[pace_buf_index][i] = ecg_out[i];
            }

            pace_buf_PreIndex = pace_buf_index;
            System.arraycopy(ecg_out, 0, ecg_outPaceBuf, 0, ecg_out.length);

            if (isEnalbeLP) {
                if (++pace_buf_index == PACE_HP_BUFF_LENGTH) {
                    pace_buf_index = 0;
                }
            } else {
                if (++pace_buf_index == PACE_BUFF_LENGTH) {
                    pace_buf_index = 0;
                }
            }
            if (1 == pace_buf[pace_buf_index][nLeadCount]) {
                bValidPacerFlag = true;
            } else {
                bValidPacerFlag = false;
            }
            isPacer[0] = bValidPacerFlag;
            if (!bValidPacerFlag) {
                break;
            }
            for (i = 0; i < nLeadCount; ++i) {
                if (EcgDataContext.LEAD_I == i) {
                    ecg_out[i] = ecg_in_UnPacer[i] + I_PACER_PLUS_VALUE;
                } else if (EcgDataContext.LEAD_II == i) {
                    ecg_out[i] = ecg_in_UnPacer[i] + II_PACER_PLUS_VALUE;
                } else {
                    ecg_out[i] = ecg_in_UnPacer[i] + V_PACER_PLUS_VALUE;
                }
            }
        } while (false);
        return ecg_out;
    }

    // 具有起搏通道时的滤波
    int[] filter_pace(int ecg_in[], int ecg_outPaceBuf[], boolean isEnalbeLP) {
        int i;
        int flag = 0;
        int[] ecg_out = new int[CHN];

        if (isEnalbeLP) {
            if (PACE_HP_BUFF_LENGTH <= pace_buf_index) {
                pace_buf_index = 0;
            }
        } else {
            if (PACE_BUFF_LENGTH <= pace_buf_index) {
                pace_buf_index = 0;
            }
        }


        if (ecg_in[12] != 0) {
            for (i = 0; i < CHN; ++i) {
                pace_buf[pace_buf_index][i] = ecg_in[i] - wave_base[i];
            }
        } else {
            for (i = 0; i < CHN; ++i) {
                pace_buf[pace_buf_index][i] = 0;
                wave_base[i] = ecg_in[i];
            }
        }
        bp067_40_250(wave_base, ecg_out, CHN, isEnalbeLP);
        System.arraycopy(ecg_out, 0, ecg_outPaceBuf, 0, ecg_out.length);
//			if (++pace_buf_index == PACE_BUFF_LENGTH) {
//				pace_buf_index = 0;
//			}

        if (isEnalbeLP) {
            if (++pace_buf_index == PACE_HP_BUFF_LENGTH) {
                pace_buf_index = 0;
            }
        } else {
            if (++pace_buf_index == PACE_BUFF_LENGTH) {
                pace_buf_index = 0;
            }
        }

        for (i = 0; i < CHN; ++i) {
            if (pace_buf[pace_buf_index][i] != 0) {
                flag = 1;
                break;
            }
        }
        if (flag == 1) {
            for (i = 0; i < CHN; ++i) {
                if (EcgDataContext.LEAD_I == i) {
                    ecg_out[i] += I_PACER_PLUS_VALUE;
                } else if (EcgDataContext.LEAD_II == i) {
                    ecg_out[i] += II_PACER_PLUS_VALUE;
                } else {
                    ecg_out[i] += V_PACER_PLUS_VALUE;
                }
//					ecg_out[i] += pace_buf[pace_buf_index][i];
            }
        }

        return ecg_out;
    }

    // 具有起搏通道时的滤波
    int[] filter_pace_ctrl(int ecg_in[]) {
        boolean enableLP = false;
        int[] ecg_out = new int[CHN];

        if (0 != ecg_in[12]) {
            if ((MAX_PACER_PLUS_CNT + 1) >= mPacerPlusCnt) {
                mPacerPlusCnt++;
            }
        } else {
            mPacerPlusCnt = 0;
        }

        if (((0 < mPacerPlusCnt) && (MAX_PACER_PLUS_CNT > mPacerPlusCnt)) ||//(ecg_in[12] != 0)||
                (!isEnableHPFilter())) {
            enableLP = false;
        } else {
            enableLP = true;
        }
//			if(!enableLP)
//			{
//			System.out.println("filter_pace_ctrl :: enableLP = "+enableLP+"  mPacerPlusCnt = "+mPacerPlusCnt) ;
//			}

        bp067_40_250(ecg_in, ecg_out, CHN, enableLP);

        return ecg_out;
    }

    // 滤波接口
    /*
     * 输出ABAB
     */
    public void filter(int ecg_out[], int ecg_in[], int len) {
        int i, j;
        int leadIndex;
        int offset;
        int[] filterInBuf = new int[13];
        int[] filterOutBuf;

        for (i = 0; i < len; ++i) {
            for (j = 0, leadIndex = 0; leadIndex < 13; leadIndex++) {    //转成ABAB
                offset = leadIndex * len;
                filterInBuf[j++] = offset + i;
            }
//			System.arraycopy(ecg_in, i * 13, filterInBuf, 0, filterInBuf.length);

//			filter_pace(&ecg_in[i * 13], &ecg_out[i * 12]);
//			filterOutBuf = filter_pace(filterInBuf);
            filterOutBuf = filter_pace_ctrl(filterInBuf);
            if (null != filterOutBuf) {
                System.arraycopy(filterOutBuf, 0, ecg_out, i * 12, filterOutBuf.length);
            }
        }
    }

    // 滤波接口
    /*
     * ecg_out --- 滤波输出：未融合起搏数据
     * ecgMergePaceOut -- 滤波输出：融合起搏数据
     * ecg_in--- 原始数据
     * DATA_COUNT_PER_LEAD --- 每导联数据长度
     * 输出ABAB
     */
    public void filter(int ecg_out[], int ecgMergePaceOut[], short ecg_in[], int[] pacerPosBuf, int DATA_COUNT_PER_LEAD) {
        int i, j;
        int leadIndex;
        int offset;
        int[] filterInBuf = new int[13];
        int[] filterOutBuf;
        int[] filterOutPaceBuf = new int[12];

        for (i = 0; i < DATA_COUNT_PER_LEAD; ++i) {
            for (j = 0, leadIndex = 0; leadIndex < 13; leadIndex++) {    //转成ABAB
                offset = leadIndex * DATA_COUNT_PER_LEAD;
                filterInBuf[j++] = ecg_in[offset + i];
            }

            if (ENABLE_NEW_FILTER) {
                filterOutBuf = filter_pace_ctrl(filterInBuf);
            } else {
                filterOutBuf = filter_pace(filterInBuf, filterOutPaceBuf);
                System.arraycopy(filterOutPaceBuf, 0, ecgMergePaceOut, i * 12, filterOutPaceBuf.length);
            }
            if (0 != filterInBuf[12]) {
                pacerPosBuf[i] = 1;
            } else {
                pacerPosBuf[i] = 0;
            }
            if (null != filterOutBuf) {
                System.arraycopy(filterOutBuf, 0, ecg_out, i * 12, filterOutBuf.length);
                if (ENABLE_NEW_FILTER) {
                    System.arraycopy(filterOutBuf, 0, ecgMergePaceOut, i * 12, filterOutBuf.length);
                }
            }
        }
    }

    // 滤波接口
    /*  滤波，带起搏
     * ecg_out --- 滤波输出：未融合起搏数据
     * ecgMergePaceOut -- 滤波输出：融合起搏数据
     * ecg_in--- 原始数据
     * DATA_COUNT_PER_LEAD --- 每导联数据长度
     * nLeadCount --- ecg_in心电数据导联数
     * bABAB --- ecg_in中数据是否为ABAB格式
     * isEnalbeLP --- 是否启用低通滤波
     * 输出ABAB
     */
    public void filter(int ecg_out[], int ecgMergePaceOut[], short ecg_in[], int[] pacerPosBuf, int DATA_COUNT_PER_LEAD, int nLeadCount, boolean bABAB, boolean isEnalbeLP) {
        int i, j;
        int leadIndex;
        int offset;
        int[] filterInBuf;// = new int[13];
        int[] filterOutBuf;
        int[] filterOutPaceBuf;// = new int [12];
        boolean[] isPacer = new boolean[1];
        isPacer[0] = false;

        if (0 < nLeadCount) {
            filterInBuf = new int[nLeadCount + 1];
            filterOutPaceBuf = new int[nLeadCount];
            for (i = 0; i < DATA_COUNT_PER_LEAD; i++) {
                if (bABAB) {
                    for (j = 0, leadIndex = 0; leadIndex < nLeadCount + 1; leadIndex++) {    //转成ABAB
                        offset = i * (nLeadCount + 1) + leadIndex;
                        filterInBuf[j++] = ecg_in[offset];
                    }
                } else {
                    for (j = 0, leadIndex = 0; leadIndex < nLeadCount + 1; leadIndex++) {    //转成ABAB
                        offset = leadIndex * DATA_COUNT_PER_LEAD;
                        filterInBuf[j++] = ecg_in[offset + i];
                    }
                }


                if (ENABLE_NEW_FILTER) {
                    filterOutBuf = filter_pace_ctrl(filterInBuf);
                } else {
                    filterOutBuf = filter_pace_delay(filterInBuf, filterOutPaceBuf, nLeadCount, isEnalbeLP, isPacer);
                    System.arraycopy(filterOutPaceBuf, 0, ecgMergePaceOut, i * nLeadCount, filterOutPaceBuf.length);
                }
//			if (0 != filterInBuf[12])
                if (isPacer[0]) {
                    pacerPosBuf[i] = 1;
                } else {
                    pacerPosBuf[i] = 0;
                }
                if (null != filterOutBuf) {
                    System.arraycopy(filterOutBuf, 0, ecg_out, i * nLeadCount, filterOutBuf.length);
                    if (ENABLE_NEW_FILTER) {
                        System.arraycopy(filterOutBuf, 0, ecgMergePaceOut, i * nLeadCount, filterOutBuf.length);
                    }
                }
            }
        }
    }

    private int getFilterDelay() {
        int delay = PACE_BUFF_LENGTH;

//		delay = COFFS_NOTCH50_250_BUFF_LENGTH/2;
//		delay += (HP067_250_BUFF_LENGTH/2);
//		
//		if(!M3Application.getInstance().isEnableHPFilter())
//		{
//			delay += (LP40_250_BUFF_LENGTH/2);
//		}
        return delay;
    }

    public boolean isEnableHPFilter() {
        return enableHPFilter;
    }

    public void setEnableHPFilter(boolean enableHPFilter) {
        this.enableHPFilter = enableHPFilter;
    }
}
